<template>
  <j-modal
    :title="title"
    :width="800"
    :visible="visible"
    :confirmLoading="confirmLoading"
    switchFullscreen
    @ok="handleOk"
    @cancel="handleCancel"
    cancelText="关闭">
    
    <a-spin :spinning="confirmLoading">
      <a-form :form="form">
      
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="昵称">
          <a-input placeholder="请输入昵称" v-decorator="['wxName', {}]" disabled/>
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="电话号">
          <a-input placeholder="请输入电话号" v-decorator="['phone', {}]" disabled/>
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="真实姓名">
          <a-input placeholder="请输入真实姓名" v-decorator="['realName', {}]" disabled/>
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="身份证号">
          <a-input placeholder="请输入身份证号" v-decorator="['idCard', {}]" disabled/>
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="身份">
          <j-dict-select-tag v-decorator="['identity', {}]"
                             :triggerChange="true"
                             placeholder="请选择身份"
                             dictCode='identity' disabled/>
          <!--<a-input placeholder="请输入身份：0:代理,1:推广,2:玩家,3:平台推广" v-decorator="['identity', {}]" />-->
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="是否进入房间">
          <j-dict-select-tag v-decorator="['start', {}]"
                             :triggerChange="true"
                             placeholder="请选择"
                             dictCode='yn' disabled/>
          <!--<a-input placeholder="请输入是否点击链接进入房间" v-decorator="['start', {}]" />-->
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="比赛结果">
          <j-dict-select-tag v-decorator="['result', validatorRules.result]"
                             :triggerChange="true"
                             placeholder="请选择比赛结果"
                             @change = "changeResult"
                             dictCode='result'/>
          <!--<a-input placeholder="请输入0：胜利，1：失败" v-decorator="['result', {}]" />-->
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          v-if="showreward"
          label="奖励">
          <a-input placeholder="请输入奖励金额" v-decorator="['reward', {}]" type="number" />
        </a-form-item>
        <!--<a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="matchId">
          <a-input placeholder="请输入matchId" v-decorator="['matchId', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="userId">
          <a-input placeholder="请输入userId" v-decorator="['userId', {}]" />
        </a-form-item>-->
		
      </a-form>
    </a-spin>
  </j-modal>
</template>

<script>
  import { httpAction } from '@/api/manage'
  import pick from 'lodash.pick'
  import moment from "moment"

  export default {
    name: "SignUpModal",
    data () {
      return {
        title:"操作",
        visible: false,
        model: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },

        confirmLoading: false,
        form: this.$form.createForm(this),
        validatorRules:{
          result:{rules: [{ required: true, message: '请选择比赛结果!' }]},
        },
        url: {
          add: "/signup/signUp/add",
          edit: "/signup/signUp/edit",
        },
        showreward:false,
      }
    },
    created () {
    },
    methods: {
      routeReload(){
        this.reloadFlag = false
        let ToggleMultipage = "ToggleMultipage"
        this.$store.dispatch(ToggleMultipage,false)
        this.$nextTick(()=>{
          this.$store.dispatch(ToggleMultipage,true)
          this.reloadFlag = true
        })
      },
      add () {
        this.edit({});
      },
      edit (record) {
        this.form.resetFields();
        this.model = Object.assign({}, record);
        this.visible = true;
        this.$nextTick(() => {
          this.form.setFieldsValue(pick(this.model,'wxName','phone','realName','idCard','identity','start','result','reward','matchId','userId'))
		  //时间格式化
        });

      },

      changeResult(value){
        console.log(value);
        if(value == 0){
          this.showreward = true;
        }else{
          this.showreward = false;
        }
      },
      close () {
        this.$emit('close');
        this.visible = false;
        this.routeReload();
      },
      handleOk () {
        const that = this;
        // 触发表单验证
        this.form.validateFields((err, values) => {
          if (!err) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            let formData = Object.assign(this.model, values);
            //时间格式化
            
            console.log(formData)
            httpAction(httpurl,formData,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
              that.close();
            })



          }
        })
      },
      handleCancel () {
        this.close()
      },


    }
  }
</script>

<style lang="less" scoped>

</style>